<?php 

class ShopBranchController extends BaseController {
    
    public function postRegister(){
        try
        {
            $input=Input::json()->all();

            //$company_id=InputHelper::getInput($input,'company_id');

            $name=InputHelper::getInput($input,'name');

            $shop_id=InputHelper::getInput($input,'shop_id');

            $warehourse_id=InputHelper::getInput($input,'warehourse_id');

            $address=InputHelper::getInput($input,'address','');
            
            $phone=InputHelper::getInput($input,'phone','');



        }
        catch(Exception $e)
        {
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }
        try{
            
            if(Shop_Branchs::Insert($name,$shop_id,$warehourse_id,$address,$phone))
            {
                return Response::json(array('status'=>'success'));
             
            }          
        }
        catch(Exception $e)
        {
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }
 
    }
    
            
       
        public function postEdit(){
             try
                {
                    $input=Input::json()->all();

                    $name=InputHelper::getInput($input,'name',null);

                    $warehourse_id=InputHelper::getInput($input,'warehourse_id',null);

                    $address=InputHelper::getInput($input,'address','');
                    
                    $phone=InputHelper::getInput($input,'phone','');

                     $branch_id=InputHelper::getInput($input,'branch_id',null);
                }
        catch(Exception $e)
        {
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }
        
        try{
            
            if(Shop_Branchs::Edit($name,$warehourse_id,$address,$phone,$branch_id))
            {
                
                return Response::json(array('status'=>'success'));
                
            }
            
        }
        catch(Exception $e)
        {
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }  
        
    }
    
       public function postDelete(){
            try
                {
                    $input=Input::json()->all();

                    $branch_id=InputHelper::getInput($input,'branch_id',null);

                }catch(Exception $e){
                    return ErrorResponse::SendErrorMessage($e->getMessage());
                } 
            try{
                
                if( Shop_Branchs::Del($branch_id)){
                    
                    return Response::json(array('status'=>'success'));   
                }
            }
        catch(Exception $e)
        {
            return ErrorResponse::SendErrorMessage($e->getMessage());
        } 
      }
        
        
        public function getSList($shop_id){
        
            try{
          
                echo json_encode(Shop_Branchs::ListBranch($shop_id));

            }
            catch(Exception $e)
            {
                return ErrorResponse::SendErrorMessage($e->getMessage());
            } 
       }
    
}

?>